/*
 * BusSemaphore.h
 *
 *  Created on: Jul 15, 2013
 *      Author: m
 */

#ifndef BUSSEMAPHORE_H_
#define BUSSEMAPHORE_H_

#include "MessageQueue2.h"

//TODO separar por ID

class BusSemaphore
{
protected:
    MessageQueue2<int> m_mq;

public:
    BusSemaphore( std::string filename );

    virtual ~BusSemaphore();

    void init();

    void destroy();

    void signal(int key =1);

    void wait(int key=1);
};

inline BusSemaphore::BusSemaphore( std::string filename ) :
        m_mq( filename )
{
}

inline BusSemaphore::~BusSemaphore()
{
}

inline void BusSemaphore::init()
{
    m_mq.destroy();
}

inline void BusSemaphore::destroy()
{
    m_mq.destroy();
}

inline void BusSemaphore::signal(int key)
{
    m_mq.put( key, 1 );
}

inline void BusSemaphore::wait(int key)
{
    m_mq.get( key );
}

#endif /* BUSSEMAPHORE_H_ */
